package com.xaicode.template.gendata.chinese;

import com.xaicode.template.gendata.base.Generator;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2022/5/24 0024 21:05
 */
public class CnMobile extends Generator {

    private static final int[] MOBILE_PREFIX = new int[]{
            130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
            145, 147,
            150, 151, 152, 153, 155, 156, 157, 158, 159,
            170, 176, 177, 178,
            180, 181, 182, 183, 184, 185, 186, 187, 188, 189};

    private static final CnMobile instance = new CnMobile();

    private CnMobile() {
    }

    public static CnMobile getInstance() {
        return instance;
    }

    @Override
    public String generate() {
        return genMobilePre() + StringUtils
                .leftPad("" + RandomUtils.nextInt(0, 99999999 + 1), 8, "0");
    }

    /**
     * 生成假的手机号，以19开头
     */
    public String generateFake() {
        return "19" + StringUtils
                .leftPad("" + RandomUtils.nextInt(0, 999999999 + 1), 9, "0");
    }

    private static String genMobilePre() {
        return "" + MOBILE_PREFIX[RandomUtils.nextInt(0, MOBILE_PREFIX.length)];
    }

}
